#!/usr/bin/env node

const Koa = require('koa');//大写，类

const app = new Koa(),//实例化
      log = console.log;

log('hello world');

app.use(async(ctx,next)=>{//M-logger
  log(`${ctx.method} ${ctx.path}`);
  //let cost = await next();
  next();//前面请求的信息，后面响应的封装

 // let cost = ctx.response.get('cost');
  log(`cost:${ctx.cost}ms`);
})

app.use((ctx,next)=>{  //M-ms
  const start = Date.now();
  next();
  const end = Date.now();
 // ctx.set('cost',end-start);
 //return end - start;
 ctx.cost = end - start;
})

app.use((ctx,next)=>{   //M-hello
  //requset parse
  
  //make response
  ctx.body = 'hello Koa';
});

app.listen(8080);




